/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.Book;
import java.io.Serializable;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Hadi
 */
@Repository //@Transactional
public class BookDao implements Serializable{
    @Autowired private SessionFactory sessionFactory;

    public void save(Book b){
        sessionFactory.getCurrentSession().saveOrUpdate(b);
    }

    public void delete(Book b){
        sessionFactory.getCurrentSession().delete(b);
    }

    public Book findById(Long id){
        return (Book) sessionFactory.getCurrentSession().get(Book.class, id);
    }

    public List<Book> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from Book").list();
    }
}
